﻿using System.Text.Json.Serialization;

namespace Medlcalcare.MVC.Models
{
    /// <summary>
    /// DeepSeek API 标准响应模型
    /// 对应官方API文档：https://platform.deepseek.com/docs/api-reference
    /// </summary>
    public class DeepSeekResponse
    {
        /// <summary>
        /// 本次请求的唯一标识ID
        /// </summary>
        //[JsonProperty("id")]
        public string Id { get; set; } = default!;

        /// <summary>
        /// 模型名称（如：deepseek-chat）
        /// </summary>
        //[JsonProperty("model")]
        public string Model { get; set; } = default!;

        /// <summary>
        /// 生成的消息选项（通常只需取第一个）
        /// </summary>
        //[JsonProperty("choices")]
        public List<DeepSeekChoice> Choices { get; set; } = new();

        /// <summary>
        /// 使用量统计
        /// </summary>
        //[JsonProperty("usage")]
        public DeepSeekUsage Usage { get; set; } = default!;

        /// <summary>
        /// 请求创建时间戳（Unix秒）
        /// </summary>
        //[JsonProperty("created")]
        public long Created { get; set; }

        /// <summary>
        /// 转换为本地DateTime
        /// </summary>
        //[JsonIgnore]
        public DateTime CreatedAt => DateTimeOffset.FromUnixTimeSeconds(Created).LocalDateTime;
    }

    /// <summary>
    /// 消息选项
    /// </summary>
    public class DeepSeekChoice
    {
        /// <summary>
        /// 消息索引（通常为0）
        /// </summary>
        //[JsonProperty("index")]
        public int Index { get; set; }

        /// <summary>
        /// 生成的消息内容
        /// </summary>
        //[JsonProperty("message")]
        public DeepSeekMessage Message { get; set; } = default!;

        /// <summary>
        /// 结束原因（stop：正常结束）
        /// </summary>
        //[JsonProperty("finish_reason")]
        public string FinishReason { get; set; } = default!;
    }

    /// <summary>
    /// 消息内容
    /// </summary>
    public class DeepSeekMessage
    {
        /// <summary>
        /// 角色（assistant/user/system）
        /// </summary>
        //[JsonProperty("role")]
        public string Role { get; set; } = default!;

        /// <summary>
        /// 实际文本内容
        /// </summary>
        //[JsonProperty("content")]
        public string Content { get; set; } = default!;
    }

    /// <summary>
    /// Token使用统计
    /// </summary>
    public class DeepSeekUsage
    {
        /// <summary>
        /// 输入Token数
        /// </summary>
        //[JsonProperty("prompt_tokens")]
        public int PromptTokens { get; set; }

        /// <summary>
        /// 输出Token数
        /// </summary>
        //[JsonProperty("completion_tokens")]
        public int CompletionTokens { get; set; }

        /// <summary>
        /// 总Token数
        /// </summary>
        //[JsonProperty("total_tokens")]
        public int TotalTokens { get; set; }
    }

    /// <summary>
    /// DeepSeek API错误响应
    /// </summary>
    public class DeepSeekErrorResponse
    {
        //[JsonProperty("error")]
        public DeepSeekError Error { get; set; } = default!;
    }
    public class DeepSeekError
    {
        /// <summary>
        /// 错误消息（如："Invalid API Key"）
        /// </summary>
        //[JsonProperty("message")]
        public string Message { get; set; } = default!;
        /// <summary>
        /// 错误类型（如："invalid_request_error"）
        /// </summary>
        //[JsonProperty("type")]
        public string Type { get; set; } = default!;
        /// <summary>
        /// HTTP状态码（如：401）
        /// </summary>
        //[JsonProperty("code")]
        public int? Code { get; set; }
    }
}
